﻿<!doctype html>
<html>
<!-- InstanceBegin template="/Templates/template1.dwt" codeOutsideHTMLIsLocked="false" -->
<head>
<meta charset="utf-8">
<!-- InstanceBeginEditable name="doctitle" -->
<title>社区管理</title>
<!-- InstanceEndEditable -->
<script type="text/javascript" src="../js/common.js"></script>
<script type="text/javascript" src="../js/checkLogin.js"></script> 
<link href="../css/Pager.css" type="text/css" rel="stylesheet" />
<script type="text/javascript" src="../js/jquery.pager.js"></script>
<script type="text/javascript" src="../js/gbRst.js"></script>
<script type="text/javascript" src="../js/doubleDate2.0.js"></script>
	<script type="text/javascript" src="../js/utils.js"></script>
<script type="text/javascript" src="../js/ajaxfileupload.js"></script> 
<script type="text/javascript" src="../js/checkLogin.js"></script> 
<script type="text/javascript" src="../js/shopSelecterNew.js"></script> 
	<script charset="utf-8" src="../js/find.js"></script>
	<script charset="utf-8" src="../js/pagination.js"></script>
<script type="text/javascript" src="../js/dataTable.js"></script>
<script type="text/javascript" src="../js/ImageBrowsing.js"></script> 
<link href="../css/style.css" type="text/css" rel="stylesheet" />
<!-- InstanceBeginEditable name="head" -->
<!-- InstanceEndEditable -->

<script type="text/javascript">
var communityList = null
var pageIndex= 1;
var pagination = null;
$(function(){
	$("#shopIsChoosed").click(function(){
		if($("#shopIsChoosed").is(":checked")){
			$("#shopName").attr("disabled",false);
			
		}else{
			$("#shopName").attr("disabled",true);

		}
	});
	

	$(".hideDiv").each(function(){
		addMargin($(this));
	})
	browse('upload','image',75,75)

});
function toAdd(){
	$("#doflag").val(1)
	$("#yinying1,#window_change").show();
}
function findCommunityList(index){
	if(IsEmpty(index)){
		index = 1
	}
	
	var title = $("#searchTitle").val()
	var shopId = ''
	if($("#shopIsChoosed").is(":checked")){	
		shopId=$("#shopName").val();
		if(IsEmpty(shopId)){
			shopId= '';
		}
	}
	
	 pagination = 
	new Pagination({
		url:'../community/find/communityList/',
		data : {
			shopId : shopId,
			name : title
			},
		success : printDataToPage,
		pageSize : 10
	});
	
}

	function printDataToPage(message) {
		communityList = message;
	dataTable({
		tbodyId : 'communityDetail ',
		 heads : ["ShopName", "title", "imageUrl", "title", "num", "notenums", "isCheckName", "isDiscussName","createdTime","createdMan","id"],
		rst : message,
		sup : {
			id : "sup",
			template : "共 [index] 条"
		},
		handler : [{
			col : 2,
			f : loadImage
		},{
			col: 10,
			f :loadUpdate
		}]
	});
}

function loadUpdate(heads,row){
	return "<input class=\"common_btn \" type=\"button\" onclick=\"toUpdate("+heads+")\" value=\"修改\"><input class=\"del\" type=\"button\" value=\"删除\" onclick=\"popPoint("+heads+")\">"
}
function toUpdate(id){
	for ( var i = 0; i < communityList.result.data.length; i++) {
		var ids= getHtmlInt(getHeadIndexValue(i, communityList, "id"));
		if(id==ids){
			var htm= "<option value='"+getHtmlInt(getHeadIndexValue(i, communityList, "shopId"))+"'>"+getHtmlString(getHeadIndexValue(i, communityList, "shopName"))+"</option>"
			$("#shopName2").html(htm);
			$("#title").val(_getStringOfJson(i, communityList, "title"));
			$("#content").val(_getStringOfJson(i, communityList, "content"));
			$("#imageUrl").val(_getStringOfJson(i, communityList, "imageUrl"));
			$("#image img").attr("src",_getStringOfJson(i, communityList, "imageUrl"));
			$("#isCheckName").val(_getStringOfJson(i, communityList, "isCheckName"));
			$("#isCheck").val(_getStringOfJson(i, communityList, "isCheck"));
			$("#updateId").val(id);
		}
	}
	$("#doflag").val(2)
	$("#yinying1,#window_change").show();
}

function loadImage(heads,row){
	return "<img src='"+heads+"'/>"
}

function saveInfo(){
	var doflag=$("#doflag").val();
	if(doflag==1){
		addInfo()
	}else if(doflag==2){
		updateInfo()
	}
}
function updateInfo(){
	var id = $("#updateId").val()
	var title= $("#title").val();
	var shopId= $("#shopName2").val();
	var content=$("#content").val();
	var isCheck = $("#isCheck").val();
	var isDiscuss= $("#isDiscuss").val();
	if(IsEmpty(shopId)){
		art.dialog({fixed:true, lock: true,content:"请选择店铺",icon:'error',ok:true});	
		return false;
	}
	if(!checkNull(title, "标题", "title")||!checkNull(content, "内容", "content")){
		return false;
	}
	
	var heads=new Array("shopId","title","content","isCheck","isDiscuss","id");
	var datas=new Array(shopId,title,content,isCheck,isDiscuss,id);
	var json = _getJsonParseEditStr(heads, datas);
	var dt = _editInfoNoResult("../community/edit", {'data':json})
	if(IsNotEmpty(dt)&&dt.state==0){
		if(!IsEmpty($("#upload").val())){
		uploadImage(id)
		}else{
			art.dialog({fixed:true, lock: true,content:"操作成功",icon:'succeed',ok:true});	
			$("#yinying1,#window_change").hide();
			restForm();
			pagination.reload()
		}
	}
}

function addInfo(){
	
	var title= $("#title").val();
	var shopId= $("#shopName2").val();
	var content=$("#content").val();
	var isCheck = $("#isCheck").val();
	var isDiscuss= $("#isDiscuss").val();
	if(IsEmpty(shopId)){
		art.dialog({fixed:true, lock: true,content:"请选择店铺",icon:'error',ok:true});	
		return false;
	}
	if(!checkNull(title, "标题", "title")||!checkNull(content, "内容", "content")){
		return false;
	}
	var heads=new Array("shopId","title","content","isCheck","isDiscuss");
	var datas=new Array(shopId,title,content,isCheck,isDiscuss);
	var json = _getJsonParseInsertStr(heads, datas);
	var dt = _insertInfoNoSucceedMessage("../community/insert", {'data':json})
	if(IsNotEmpty(dt)&&dt.state==0){
		var id= getHtmlInt(getHeadIndexValue(0, dt, "id"));
		uploadImage(id)
	}
}
function uploadImage(id){
	
	$.ajaxFileUpload({
		url :"../community/upload/image/community/"+id,
		secureuri : false,
		fileElementId : 'upload',
		dataType : 'json',
		success : function(data){
			if (data.state == 0) {
				art.dialog({fixed:true, lock: true,content:"操作成功",icon:'succeed',ok:true});
				pagination.reload()
				restForm()
			$("#yinying1,#window_change").hide();
	}else if(data.state == 1){
				art.dialog({fixed:true, lock: true,content:"操作失败",icon:'error',ok:true});	
				}
			browse('upload','image',75,75)

		},
		error : function(data) {
			art.dialog({fixed:true, lock: true,content:"图片上传失败",icon:'error',ok:true});	
			browse('upload','image',75,75)

			return false;
		}
	});

}

function deleteInfo(id){
	var dt = _deleteInfo("../community/del", {'id':id})
	if(dt.state==0){
		pagination.reload()
	}
}

function popPoint(id){
	art.dialog({fixed:true, lock: true,content:"确认删除该条数据？",icon:'question',ok: function(){ deleteInfo(id)},cancel:true});
	}
	
function restForm(){
	$("#title").val("");
	$("#shopName2").html("");
	$("#content").val("");
	$("#imageUrl").val("");
	$("#upload").val("");
}	

</script>
</head>

<body>
<!-- InstanceBeginEditable name="EditRegion3" --> 
<div id="yinying1"></div>
<div id="window_change" class="member_search hideDiv" style="width:520px;z-index: 150">
    <div class="closeTop"><span class="closeThe" onclick="closeParent($(this))"><img src="../images/close.png"></span></div>
    <input type="hidden" id="doflag" value="1">
    <input type="hidden" id="updateId">
    <p>
      <label><span> 店面：</span>
        
        <select id="shopName2" onclick="openShopListPanel(this)"  style="height:20px;">
        </select>
      </label>
   </p>
   <p>
      <label><span>社区主题名称：</span>
        <input type="text" id="title"><!-- <br> <span id="NameTip" style="display:none;"></span> --> 
      </label>
    </p>
    <p>
<span>图片：</span>
<input id="imageUrl" class="isDisabled" type="text">
<input class="btn" type="button" value="...">
<input id="upload" class="file isDisabled" type="file" name="upload">
<span id="image" class="onlyImgSrc"><img src="../images/img_activities1.jpg"></span>
</p>
    <p>
      <label><span>社区简介：</span>
        <textarea id="content" style="width:394px;"></textarea>
      </label>
    </p>
      <p>
      <label>
      	<span>允许评论：</span>
        <select id="isDiscuss">
          <option value="0" >是</option>
          <option value="1">否</option>
        </select>
      </label>
  		<label><span>审核：</span>
        <select id="isCheck">
          <option value="0">是</option>
          <option value="1">否</option>
        </select>
      </label>
     
    </p>
    <div class="submit_btn">
      <input type="button" value="保存信息" class="common_btn" id="close_this" onclick="saveInfo()">
    </div>
  </div>
<div class="container" id="container">
  <div class="container_R fr">
    <div class="place">社区</div>
  		<div class="member_search">
      <p><span>
        <input type="checkbox" id="shopIsChoosed" style="width:auto;">店面：</span>
        <select id="shopName" class="shopName" onclick="openShopListPanel(this)" disabled="disabled">
        </select>
        <span>社区名称：</span>
        <input type="text" id="searchTitle" class="absoluteTxt" >
      <input class="btn" id="research" name="查询" type="button" value="查询" onClick="findCommunityList(1)" style="float:right;margin-right:12px;" ></p>
      </div>
   	<table width="100%" border="0" cellspacing="1" cellpadding="0" class="member_list">
    	<caption><strong>社区列表       <span id="sup">共：1条</span> </strong> <input type="button" value="增加" class="common_btn" onclick="toAdd()"></caption>
    	<thead>
    	<tr>
    		<th>店面</th>
    		<th>社区名称</th>
        	<th>图片</th>
        	<th>社区简介</th>
        	<th>访问数</th>
        	<th>帖子数</th>
        	<th>审核</th>
        	<th>允许评论</th>
        	<th>创建时间</th>
        	<th>创建人</th>
        	<th>操作</th>
        </tr>
        </thead>
        <tbody id="communityDetail"></tbody>
    </table>
  </div>
  <div class="fc"></div>
</div>
<!-- InstanceEndEditable --> 
<script type="text/javascript" src="../js/header.js"></script> 
<script type="text/javascript" src="../js/left.js"></script> 
<script type="text/javascript" src="../js/footer.js"></script> 
<script type="text/javascript">
addMargin($(".hideDiv"))
clearThis("absoluteTxt");
</script>
</body>
<!-- InstanceEnd -->
</html>
